<?php
/**
 * StatZone default controller
 * 
 * @package    USS.StatZone
 * @subpackage Components
 * @link www.ugenix.co.za www.statzone.co.za
 * @license		Commercial
 * @author Salie Hendricks
 */

// no direct access
defined('_JEXEC') or die('Restricted access');

// Require the base controller
require_once (JPATH_COMPONENT.DS.'controller.php');

// Set the table directory
JTable::addIncludePath(JPATH_ADMINISTRATOR.DS.'components'.DS.'com_statzone'.DS.'tables');

$controllerName = JRequest::getCmd( 'c', 'club' );
if($controllerName == 'club') 
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club',true);
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team');
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player');
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard');
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting');
    
}
else if($controllerName == 'team') 
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club');
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team',true);
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player');
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard');
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting');
}
else if($controllerName == 'player') 
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club');
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team');
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player',true);
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard');
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting');
}
else if($controllerName == 'scorecard') 
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club');
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team');
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player');
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard',true);
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting');
}
else if($controllerName == 'setting') 
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club');
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team');
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player');
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard');
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting',true);
}
else
{
    JSubMenuHelper::addEntry(JText::_('Clubs'), 'index.php?option=com_statzone&c=club',true);
    JSubMenuHelper::addEntry(JText::_('Teams'), 'index.php?option=com_statzone&c=team');
    JSubMenuHelper::addEntry(JText::_('Players'), 'index.php?option=com_statzone&c=player');
    JSubMenuHelper::addEntry(JText::_('Scorecards'), 'index.php?option=com_statzone&c=scorecard');
    JSubMenuHelper::addEntry(JText::_('Settings'), 'index.php?option=com_statzone&c=setting');
}

switch ($controllerName)
{
	default:
		$controllerName = 'club';
		// allow fall through

	case 'club' :
        // Temporary interceptor
		$task = JRequest::getCmd('task');
		if ($task == 'listclubs') 
        {
			$controllerName = 'club';
		}

		require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
		$controllerName = 'StatZoneController'.$controllerName;

		// Create the controller
		$controller = new $controllerName();

		// Perform the Request task
		$controller->execute( JRequest::getCmd('task') );

		// Redirect if set by the controller
		$controller->redirect();
		break;
    case 'player' :
        $task = JRequest::getCmd('task');
		$controllerName = 'player';
		require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
		$controllerName = 'StatZoneController'.$controllerName;

		// Create the controller
		$controller = new $controllerName();

		// Perform the Request task
		$controller->execute( JRequest::getCmd('task') );

		// Redirect if set by the controller
		$controller->redirect();
		break;
    case 'scorecard' :
        $task = JRequest::getCmd('task');
		$controllerName = 'scorecard';

        //echo 'heres the task requested -->'.$task;
		require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
		$controllerName = 'StatZoneController'.$controllerName;

		// Create the controller
		$controller = new $controllerName();

		// Perform the Request task
		$controller->execute( JRequest::getCmd('task') );

		// Redirect if set by the controller
		$controller->redirect();
		break;
        
	case 'team':
		// Temporary interceptor
		$task = JRequest::getCmd('task');
		$controllerName = 'team';

		require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
		$controllerName = 'StatZoneController'.$controllerName;

		// Create the controller
		$controller = new $controllerName();

		// Perform the Request task
		$controller->execute( JRequest::getCmd('task') );

		// Redirect if set by the controller
		$controller->redirect();
		break;
    
    case 'setting':
		// Temporary interceptor
		$task = JRequest::getCmd('task');
		$controllerName = 'setting';

		require_once( JPATH_COMPONENT.DS.'controllers'.DS.$controllerName.'.php' );
		$controllerName = 'StatZoneController'.$controllerName;

		// Create the controller
		$controller = new $controllerName();

		// Perform the Request task
		$controller->execute( JRequest::getCmd('task') );

		// Redirect if set by the controller
		$controller->redirect();
		break;
}
?>
